import _ from 'lodash';
import { useCommonStore } from "@jzl/stores";

export const isGroup = (data) => {
  let id = _.get(data, 'mb_group_id');
  return !_.get(data, 'mb_code') && id > 0;
}

export const isMbRoot = (data) => {
  return _.get(data, 'mb_code') && _.get(data, 'parent_id') == -1;
}

export const isApp = (data) => {
  return !isGroup(data) && !isMbRoot(data) && (data?.isApp || data?.nodeType === 'app')
}

export const canEdit = (data) => {
  let editing = false;

  if(data) {
    if(data.id === -100) {
      editing = false;
    } else if(data.project_id === -1) {
      if(useCommonStore().loginUser?.type === '_SUPER') {
        editing = true;
      } else {
        editing = false;
      }
    } else {
      editing = true;
    }
  }

  return editing;
}
